package com.qf;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsOrder;
import com.qf.pojo.DtsShipChannel;
import com.qf.service.OrderService;
import com.qf.service.ShipChannelService;
import com.qf.util.ResponseUtil;
import com.qf.vo.ShipChannelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsOrder;
import com.qf.pojo.DtsShipChannel;
import com.qf.service.OrderService;
import com.qf.service.ShipChannelService;
import com.qf.util.ResponseUtil;
import com.qf.vo.ShipChannelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author sunyamei
 * @version V1.0
 * @Project javase2203
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/7/28 16:22
 */
@CrossOrigin("*")
@RequestMapping("/order")
@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private ShipChannelService shipChannelService;

    @GetMapping("/list")
    public  Object queryByPage(Integer user_id,String order_sn,String order_status,Integer page,Integer limit,String sort,String order){

        IPage<DtsOrder> iPage = orderService.queryByPage(user_id, order_sn, order_status, page, limit, sort, order);

        //查询总条数
        long total = iPage.getTotal();

        //查询每页业务
        List<DtsOrder> list = iPage.getRecords();

        //封装map
        HashMap<String, Object> data = new HashMap<>();
        data.put("total", total);
        data.put("items", list);
        return ResponseUtil.ok(data);

    }

    /**
     *快递列表
     * @return
     */
    @RequestMapping("/listShipChannel")
    public Object findShipChannel(){

       List<ShipChannelVo> shipChannel = shipChannelService.findShipChannel();

       //封装
       Map<String, Object> data = new HashMap<>();
       data.put("shipChannelList", shipChannel);

      return ResponseUtil.ok(data);
    }


    /**
     * 订单详情
     * @param id
     * @return
     */
    public  Object findById(Integer id){

       orderService.findById(id);
        return  ResponseUtil.ok(id);

    }
}
